<template>
  <div id="app">
    <!-- 头部 -->
    <div class="header">
      <span
        @click="$router.go(-1)"
        v-if="$route.path !== '/home'"
        class="goback"
      >
        <van-icon style="margin-right:3px;" name="arrow-left" />返回
      </span>
      <span
        class="goadd"
        v-if="$route.path === '/search'"
        @click="$router.push('/addgoods')"
        >添加</span
      >
      <span class="proTitle">黑马商城</span>
    </div>
    <!-- 子组件 -->
    <transition>
      <router-view></router-view>
    </transition>
    <!-- 底部 tabbar -->
    <van-tabbar v-model="active">
      <van-tabbar-item to="/home">
        <i slot="icon" class="iconfont icon-index-fill"></i>
        <span>首页</span>
      </van-tabbar-item>
      <van-tabbar-item to="/member">
        <i slot="icon" class="iconfont icon-icon_zhanghao"></i>
        <span>会员</span>
      </van-tabbar-item>
      <van-tabbar-item to="/shopcar" icon="shopping-cart-o" :info="allCount"
        >购物车</van-tabbar-item
      >
      <van-tabbar-item to="/search" icon="search">搜索</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'app',
  data() {
    return {
      active: 0
    }
  },
  computed: {
    ...mapGetters(['allCount'])
  },
  created() {
    this.$store.dispatch('getCarList')
  },
  methods: {}
}
</script>

<style lang="less" scoped>
#app {
  padding: 40px 0 50px 0;
  width: 100%;
  height: 100%;
  background: #fff;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  .header {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    color: #fff;
    background: #1989fa;
    font-size: 14px;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99;
    .goback {
      position: fixed;
      top: 0px;
      display: flex;
      align-items: center;
      left: 15px;
    }
    .goadd {
      position: fixed;
      top: 0px;
      display: flex;
      align-items: center;
      right: 15px;
    }
  }
}

// 页面切换动画
.v-enter,
.v-leave-to {
  opacity: 0;
  transform: translateX(-500px);
}
.v-enter-active,/*入场动画时间段*/
.v-leave-active {
  /*离场动画时间段*/
  transition: all 0.2s ease-in;
}
</style>
